﻿@using NB.MGJ.Model;
@{
    Layout = null;
    AntiFake_Digitcode a = ViewBag.model as AntiFake_Digitcode;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>中国品牌365验证中心</title>
    <link href="https://cdn.bootcss.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-1.10.2.min.js"></script>

    <style>
        ul > li {
            list-style: none;
        }

        body {
            font-family: 微软雅黑;
            background: #ffffff;
            height: 100vh;
            overflow: auto;
            margin: 0 auto;
            width: 90%;
            /*position: absolute;
            width:90%;
           left:5%;
           height:100%;*/
        }

        #link {
            text-align: right;
            padding: 20px;
        }

            #link > a {
                color: #888;
                padding: 0 10px;
            }

                #link > a:hover {
                    text-decoration: none;
                    color: #509a55;
                }

        #head {
            text-align: center;
            position: relative;
            padding-bottom: 20px;
        }

        #backIndex {
            position: absolute;
            top: 0;
            left: 0;
            color: #888;
            margin-top: 20px;
            margin-left: 20px;
            display: inline-block;
            text-decoration: none;
            font-weight: 700;
            font-size: 20px;
        }

        #topBanner {
            min-height: 55%;
            background: url("/Content/WebImg/u2.png");
            background-size: 100% 100%;
            border-radius: 4px;
            position: relative;
        }

        .Title {
            color: #509A55;
            text-align: center;
            margin: 0;
            padding: 30px 0;
        }



        .titleBorder {
            border-bottom: 5px solid #999;
            padding-bottom: 5px;
        }

        #topBannerBottom {
            height: 60px;
            width: 100%;
            background: rgba(0,0,0,0.3);
            position: absolute;
            bottom: 0;
            line-height: 60px;
            color: #FFF;
            display: flex;
            align-items: center;
            white-space: nowrap;
            display: none;
        }

        #results {
            display: none;
            padding: 50px 0;
            background: #f7f7f7;
            margin-top: -40px;
            border-radius: 4px;
        }

        #QrCodeDiv {
            /*display:flex;
            justify-content:center;
            align-items:center;*/
        }

            #QrCodeDiv > img {
                width: 300px;
                height: 180px;
                display: block;
                margin: 0 auto;
                border-radius:4px;
            }

        #resultsUl {
            padding: 0;
        }

            #resultsUl > li {
                margin-bottom: 10px;
            }

                #resultsUl > li > span:nth-child(1) {
                    color: #999;
                }

                #resultsUl > li > span:nth-child(2) {
                    color: #444;
                }

        #RecordTable {
            margin-top: 20px;
            display: none;
        }

        input::-webkit-outer-spin-button,
        input::-webkit-inner-spin-button {
            -webkit-appearance: none !important;
            margin: 0;
        }

        .btn {
            background: #5cb85c !important;
            border-color: #5cb85c !important;
        }

        .triangle-down {
            width: 0;
            height: 0;
            border-left: 5px solid transparent;
            border-right: 5px solid transparent;
            border-top: 10px solid #5cb85c;
            margin-left: 4px;
        }

        #errorBox {
            position: relative;
            top: -80px;
            left: 5px;
            display: none;
        }




        footer {
            /*position: absolute;
            bottom: 0;*/
            color: #999;
            width: 100%;
            padding: 10px 0;
            display: flex;
            align-items: center;
        }

        #buttomimgs {
            text-align: center;
        }

            #buttomimgs img {
                margin: 5px 10px;
            }

        #buttom {
            margin-top: 10px;
        }

            #buttom p {
                margin: 5px 0;
                text-align: center;
            }
    </style>
</head>
<body>
    <div id="link">
        <a href="//www.shnb12315.com/">访问官网</a>
        <a href="//eng365.nb12365.com/c/toushu.asp">在线投诉维权</a>
        <a href="//eng365.nb12365.com/c/365.asp">一键曝光</a>
        <a href="//shnb12315.com/contact.asp">防伪咨询</a>
        <a>手机查询</a>
    </div>
    <div id="head">
        <a href="" id="backIndex">
            <span class="glyphicon glyphicon-circle-arrow-left" style="color:#5CB85C;"></span>
            返回首页
        </a>
        <img src="//shnbbucket.oss-cn-beijing.aliyuncs.com/20180123153544.png" />
    </div>
    <div id="topBanner">
        <h2 class="Title">
            防伪<span class="titleBorder">查询</span>结果
        </h2>
        <div class="container-fluid" style="margin-top:50px;">
            <div class="col-sm-6 col-md-offset-3">
                <div class="col-sm-8" style="position:relative">
                    <input type="number" id="FWtxt" placeholder="请输入防伪码" oninput="Validator(this)" class="form-control" />
                    <div id="errorBox">
                        <div class="btn btn-success">输入格式不对</div>
                        <div class="triangle-down"></div>
                    </div>
                </div>
                <div class="col-sm-3"><button class="btn btn-success" onclick="query()">防伪查询&nbsp;<span class="glyphicon glyphicon-search"></span></button></div>
            </div>
        </div>
        <div id="topBannerBottom">
            <span id="resultNum" style="height: 34px; width: 34px; border: 2px solid #FFF; display: inline-block; border-radius:17px;margin:15px;line-height:32px;text-align:center;font-size:24px">1</span>
            <span id="resultText" style="font-weight:700"></span>
        </div>
    </div>
    <div id="results">
        <div class="container">
            <div class="col-sm-5" id="QrCodeDiv">
                <img id="QrCodeImg" src="~/Content/WebImg/empty.png">
                <div style="color:#999;margin:20px 0 0 0">
                    查询小贴士：产品所贴防伪标识应与上方查询结果标识图案基本一致，数字编码以产品标识为准
                </div>
            </div>
            <div class="col-sm-6 col-sm-offset-1">
                <ul id="resultsUl"></ul>
                @*<button id="resultsBtn" class="btn btn-success" onclick="ShowRecord()">
                    查询记录
                        <span class="glyphicon glyphicon-triangle-bottom"></span>
                    </button>*@
                <div class="btn-group" id="resultsBtn" onclick="ShowRecord()">
                    <button type="button" class="btn btn-success">
                        查询记录 <span class="caret"></span>
                    </button>
                </div>


                <table id="RecordTable" class="table table-hover table-bordered">
                    <thead>
                        <tr>
                            <td>查询时间</td>
                            <td>查询地点</td>
                            <td>查询方式</td>
                            <td>查询IP</td>
                            <td>是否异常</td>
                        </tr>
                    </thead>
                    <tbody id="RecordTbody"></tbody>
                </table>
            </div>
        </div>
    </div>
    <footer>
        <div style="flex:1">
            <div id="buttomimgs">
                <img src="~/Content/WebImg/u5.png" />
                <img src="~/Content/WebImg/u7.png" />

                <img src="~/Content/WebImg/u9.png" />

                <img src="~/Content/WebImg/u11.png" />

                <img src="~/Content/WebImg/u13.png" />
            </div>
            <div id="buttom">
                <p>
                    已通过ISO9001:2008质量管理体系标准要求 认证编号：11712QU0052-02 ROS 防伪技术评审证书编号：FWPS-11-118
                </p>
                <p> 软件著作V2.0证书号：0528663 软件产品登记证书编码：沪DGY-2013-1129 安备案号:31011202003588 </p>
                <p>
                    技术支持：上海诺标  版权所有    全国免费咨询、订单、物流、投诉热线：4006 - 12315 - 3         沪ICP备14005269号-2
                </p>
                <p>技术支持：码管家云系统 版权所有</p>
            </div>
        </div>
        <img src="//shnbbucket.oss-cn-beijing.aliyuncs.com/20180123155223.png" alt="Alternate Text" />
    </footer>
</body>
</html>
<script>
    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
                + " " + date.getHours() + seperator2 + date.getMinutes()
                + seperator2 + date.getSeconds();
        return currentdate;
    }

    var Code;
    function query() {
        Code = $("#FWtxt").val();

        if (Code.length > 24 || Code.length < 18) {
            $("#errorBox").show();
            $("#results").hide();
            return
        }


        $("#btn").prop('disabled', "true");
        $.ajax({
            url: ACTION_URL("GetFWSearchList", "Home"),
            data: JSON,
            data: { "Code": Code },
            success: function (data_) {
                
                var data = JSON.parse(data_)
                resultInfo = JSON.parse(data.results)
                if (resultInfo == "2") {
                    $("#resultText").text("尊敬的消费者您好!您查询的产品已实施召回，请联系当地销售商做退回处理！");
                    $("#resultNum").text("?")
                    $("#topBannerBottom").show()
                    $("#results").hide()
                    $(".container").hide();
                } else {
                    if (resultInfo != "-1") {
                        LogInfo = JSON.parse(data.loginfo).reverse()
                        $("#resultNum").text(data.num)

                        if (data.num > 1) {
                            $("#resultText").text("您所查询的" + resultInfo[0].EnterpriseName + "产品已于" + LogInfo[LogInfo.length - 1].QueryTime + "被首次查询，谨防假冒！");
                        } else if (data.num == 1 && resultInfo[0].EnterpriseUse == "") {
                            $("#resultText").text('您好！您所查询的是' + resultInfo[0].EnterpriseName + '生产的' + resultInfo[0].ProductName + '品牌产品，是正牌产品的标识，欢迎您再次选购！')
                        }
                        var Ulhtml = [
                            '<li class="row">',
                                '<span class="col-sm-3 text-right">总共查询次数：</span>',
                                '<span>' + data.num + '</span>',
                            '</li>',
                            '<li class="row">',
                                '<span class="col-sm-3 text-right">首次查询时间：</span>',
                                '<span>' + LogInfo[LogInfo.length - 1].QueryTime + '</span>',
                            '</li>'].join("")
                        if (LogInfo[LogInfo.length - 1].QueryCity != "") {
                            Ulhtml += ['<li class="row">',
                                '<span class="col-sm-3 text-right">首次查询位置：</span>',
                                '<span>' + LogInfo[LogInfo.length - 1].QueryCity + '</span>',
                            '</li>'].join("")
                        }

                        Ulhtml += ['<li class="row">',
                                '<span class="col-sm-3 text-right">当前查询时间：</span>',
                                '<span>' + getNowFormatDate() + '</span>',
                            '</li>'
                        ].join("")

                        if (resultInfo[0].EnterpriseUse == "") {
                            Ulhtml += ['<li class="row">',
                                 '<span class="col-sm-3 text-right">企业名称：</span>',
                                 '<span>' + resultInfo[0].EnterpriseName + '</span>',
                             '</li>'].join("")
                        }
                        else {
                            Ulhtml += ['<li class="row">',
                                '<span class="col-sm-3 text-right">企业名称：</span>',
                                '<span>' + resultInfo[0].EnterpriseUse + '</span>',
                            '</li>'].join("")
                        }

                        if (resultInfo[0].ProductName == "") {
                            Ulhtml += ['<li class="row">',
                                '<span class="col-sm-3 text-right">产品名称：</span>',
                                '<span>产品暂未绑定</span>',
                            '</li>'].join("")
                        }
                        else {
                            Ulhtml += ['<li class="row">',
                                '<span class="col-sm-3 text-right">产品名称：</span>',
                                '<span>' + resultInfo[0].ProductName + '</span>',
                            '</li>'].join("")
                        }

                        $("#resultsUl").html(Ulhtml)

                        var RecordTbodyHtml;
                        if (LogInfo.length == 1) {
                            $("#resultsBtn").hide();
                        } else {
                            for (var i = 0; i < LogInfo.length ; i++) {
                                RecordTbodyHtml += [
                                    '<tr>',
                                        '<td>' + LogInfo[i].QueryTime + '</td>',
                                        '<td>' + LogInfo[i].QueryProvince + '</td>',
                                        '<td class="QueryType">' + LogInfo[i].QueryType + '</td>',
                                        '<td>' + LogInfo[i].QueryIp + '</td>'
                                ].join("")
                                if (i != LogInfo.length - 1) {
                                    RecordTbodyHtml += ['<td class="QueryValid">重复查询</td>',
                                   '</tr>'].join("")
                                } else {
                                    RecordTbodyHtml += ['<td class="QueryValid">首次查询</td>',
                                   '</tr>'].join("")
                                }
                            }
                            $("#resultsBtn").show();
                        }


                        $("#RecordTbody").html(RecordTbodyHtml)
                        $(".QueryType").each(function () {
                            var index = $(this).text()
                            switch (index) {
                                case "0":

                                    $(this).text("微信")
                                    break;
                                case "1":
                                    $(this).text("网站")
                                    break;
                                case "2":
                                    $(this).text("短信")
                                    break;
                                case "3":
                                    $(this).text("语音")
                                    break;

                            }
                        })
                        if (resultInfo[0].LabelImage != "") { $("#QrCodeImg").attr("src", resultInfo[0].LabelImage) }
                        $("#RecordTable").hide()
                        $("#topBannerBottom").show()
                        $("#results").show()
                    } else {
                        $("#resultText").text("您所查询的防伪码不存在，防伪码应是不含空格的纯数字编码，请核对，谨防假冒！")
                        $("#resultNum").text("?")
                        $("#topBannerBottom").show()
                        $("#results").hide()
                    }

                }
            },

            error: function () {
                $("#errorBox").show();
                $("#results").hide();
            }
        });

        $("#btn").Enable = false;
    }

    function ShowRecord() {
        $("#RecordTable").toggle()
    }


    function ACTION_URL(actionName, controllerName) {
        var _actionUrl = '@Url.Action("ActionName", "ControllerName")';
        return _actionUrl.replace("ActionName", actionName).replace("ControllerName", controllerName);
    }
    function add() {
        var search = $("#FWtxt").val();

        //$.ajax({
        //    url: ACTION_URL("AddFWSearchList", "Home"),
        //    data: JSON,
        //    data: {"Search": search},
        //    success: function (data) {

        //    },
        //    error: function () {
        //        alert("你输入的码不正确！")
        //    }

        //});

    }


    function DisableBtn(_this) {
        if ($(_this).val() != search) {
            $("#btn").removeAttr('disabled');
        } else {
            $("#btn").prop('disabled', "true");
        }
    }

    $(function () {
        var url = window.location.href;
        if (url.indexOf("?") > 0) {
            var FwCode = url.substring(url.indexOf("?") + 1)
            $("#FWtxt").val(FwCode);
            query();
        }
    })


    function get_ip_address(_ip) {
        $.ajax({
            url: "//saip.market.alicloudapi.com/ip",
            type: "GET",
            dataType: 'json',
            beforeSend: function (xhr) {
                xhr.setRequestHeader("Authorization", "APPCODEb16ac0eda1754f5a866056e3808801ce");
            },
            data: {
                ip: _ip
            },
            success: function (r) {
                //do
            }
        })
    }
    //get_ip_address("101.81.217.110");
    $("#errorBox").click(function () {
        $(this).hide()
    })
    function Validator(_this) {
        var length = $(_this).val().length;
        if (length > 24 || length < 18) {
            $("#errorBox").show();
            $("#results").hide();
            $("#btn").prop('disabled', "true");
        } else {
            $("#errorBox").hide();
            $("#btn").prop('disabled', "false");
        }
    }
</script>
